package org.example.handler;

import org.example.common.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public @ResponseBody R handlerException(Exception ex){
        if(ex instanceof RuntimeException){
            return R.failed(ex.getMessage());
        }else {
            return R.failed("系统错误,请稍后再试！");
        }
    }
}